package com.isky.visual.util;

import java.util.ArrayList;
import java.util.List;

/**
 * @version v1.0
 * @ProjectName visual_parent
 * @ClassName StringUtils
 * @Description TODO 字符串的工具类
 * @Author wudl
 * @Date DATE{TIME}
 */

public class StringUtil {


    /**
     * 根据传入的sql 将sql 切分后将列分离出来
     *
     * @param sql
     * @return
     */
    public static List<String> getStrToSplit(String sql) {
        List<String> result = new ArrayList<>();
        String[] selectColumns = sql.split("from");
// IFNULL(max(a.id ),0) as id,IFNULL(max(b.user_id ),0) as user_id,IFNULL(max(c.id ),0) as id,IFNULL(max(a.user_code ),0) as user_code

        String columns = selectColumns[0].replace("select", "").trim();
        String[] cloumnArr = columns.split(",");
        for (String key : cloumnArr) {
            String[] values = key.split("as");
            if (values.length == 2) {
                result.add(values[1].trim());
            } else {
              //  result.add(values[0].trim());
            }
        }
        return result;
    }


}
